/*-------------------------------------------------------------------------
 *
 * committsdesc.c
 *	  访问/transam/commit_ts.c 的 rmgr 描述例程
 *
 * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 *
 * IDENTIFICATION
 *	  src/backend/access/rmgrdesc/committsdesc.c
 *
 *-------------------------------------------------------------------------
 */
#include "postgres.h"

#include "access/commit_ts.h"
#include "utils/timestamp.h"


void commit_ts_desc(StringInfo fc_buf, XLogReaderState *fc_record)
{
	char	   *fc_rec = XLogRecGetData(fc_record);
	uint8		fc_info = XLogRecGetInfo(fc_record) & ~XLR_INFO_MASK;

	if (fc_info == COMMIT_TS_ZEROPAGE)
	{
		int			fc_pageno;

		memcpy(&fc_pageno, fc_rec, sizeof(int));
		appendStringInfo(fc_buf, "%d", fc_pageno);
	}
	else if (fc_info == COMMIT_TS_TRUNCATE)
	{
		xl_commit_ts_truncate *fc_trunc = (xl_commit_ts_truncate *) fc_rec;

		appendStringInfo(fc_buf, "pageno %d, oldestXid %u",
						 fc_trunc->pageno, fc_trunc->oldestXid);
	}
}

const char * commit_ts_identify(uint8 fc_info)
{
	switch (fc_info)
	{
		case COMMIT_TS_ZEROPAGE:
			return "ZEROPAGE";
		case COMMIT_TS_TRUNCATE:
			return "TRUNCATE";
		default:
			return NULL;
	}
}
